package main

import (
	"fmt"
	"html/template"
	"net/http"
)

type Stu struct {
	Name string
	Age  int
}

func main() {
	http.HandleFunc("/subA", func(w http.ResponseWriter, r *http.Request) {
		tpl, err := template.New("index.tpl").Delims("{[", "]}").ParseFiles("./index.tpl")
		if err != nil {
			fmt.Printf("解析出错,err:%v", err)
		}
		err = tpl.Execute(w, "subA")
		if err != nil {
			fmt.Printf("渲染模版出错,err:%v", err)
		}
	})
	http.HandleFunc("/subA", func(w http.ResponseWriter, r *http.Request) {

		tpl, err := template.ParseFiles("./template/common.tpl", "./template/subA.tpl")
		if err != nil {
			fmt.Printf("解析出错,err:%v", err)
		}
		err = tpl.Execute(w, "subA")
		if err != nil {
			fmt.Printf("渲染模版出错,err:%v", err)
		}
	})
	http.HandleFunc("/subB", func(w http.ResponseWriter, r *http.Request) {

		tpl, err := template.ParseFiles("./template/common.tpl", "./template/subA.tpl")
		if err != nil {
			fmt.Printf("解析出错,err:%v", err)
		}
		err = tpl.Execute(w, "subB")
		if err != nil {
			fmt.Printf("渲染模版出错,err:%v", err)
		}
	})

	http.ListenAndServe(":9090", nil)
}
